// pages/productDetail/productDetail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodid:"",
    indicatorDots:true,
    autoplay:true,
    interval:5000,
    duration:500,
    imgUrl:[
      '../../images/ruixing2.jpeg',
      '../../images/ruixing4.jpeg'
    ],
    detailImgUrl:[
      '../../images/ruixing12.jpg',
      '../../images/ruixing3.jpeg'
    ],
    title:"生耶拿铁" ,
    scale_exist:true, //规格选项存在
    scale_arr:["大杯","中杯","小杯"],
    suger_type_exist:true, //唐的类型 普通糖 果糖。。。
    suger_type_arr:["果糖","0能量糖"],  
    suger_degree_exist:true, //糖的甜度
    suger_degree_arr:["全糖", "7成糖","5成糖","无糖"],
    temperature_exist:true, //温度
    temperature_arr:["常温","冰","热"],
    add_material_exist:true, //加料
    add_material_arr:["常规","椰果","啵啵","西米露","爆爆珠"],
    currentScale:0,
    currentScaleText:"大杯",
    currentSuger_type:0,
    currentSuger_typeText:"果糖",
    currentSuger_degree:0,
    currentSuger_degreeText:"全糖",
    currentTemperature:0,
    currentTemperatureText:"常温",
    currentAddMaterial:0,
    currentAddMaterialText:"常规",
    oldPrice:'29',
    newPrice:'18'  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    //此时的{goodid: "08afb6fb-c52c-4f42-a4c5-aa53bc21c275"}
    // that.setData({
    //   goodid:options.goodid
    // })
  },
  
  //改大被 中杯 小杯
  change_scale(e){  
    let that = this
    let text = e.currentTarget.dataset.text
    let index =  e.currentTarget.dataset.index
    let currentText = that.data.scale_arr[index]
    that.setData({
      currentScale:index,
      currentScaleText:currentText
    })
  },

  //改变糖的类型
  change_suger_type(e){
    let that = this
    let text = e.currentTarget.dataset.text
    let index =  e.currentTarget.dataset.index
    let currentText = that.data.suger_type_arr[index] 
    that.setData({
      currentSuger_type:index,
      currentSuger_typeText:currentText
    })
  },

  change_suger_degree(e){
    let that = this
    let text = e.currentTarget.dataset.text
    let index =  e.currentTarget.dataset.index
    let currentText = that.data.suger_degree_arr[index] 
    that.setData({
      currentSuger_degree:index,
      currentSuger_degreeText:currentText
    })
  },

  change_temperature(e){
    let that = this
    let text = e.currentTarget.dataset.text
    let index =  e.currentTarget.dataset.index
    let currentText = that.data.temperature_arr[index] 
    that.setData({
      currentTemperature:index,
      currentTemperatureText:currentText
    })
  },

  change_add_material(e){
    let that = this
    let text = e.currentTarget.dataset.text
    let index =  e.currentTarget.dataset.index
    let currentText = that.data.add_material_arr[index] 
    that.setData({
      currentAddMaterial:index,
      currentAddMaterialText:currentText
    })
  },

  /**立即购买按钮 */
  buyNow(){
    let that = this
    /*此处获得 单价 数量 优惠 产品id*/

    wx.navigateTo({
      url: '../buyNow/buyNow',
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  // 1、点击+数量价格变化
  onBindPlus: function (e) {
    this.tapCalculation(e);
  },
  // 2、点击-数量价格变化
  onBindMinus: function (e) {
    this.tapCalculation(e);
  },
  // 3、输入数量价格变化
  onGetNum: function (e) {
    this.tapCalculation(e);
  },

  // 点击数量更新数据及计算价格
  tapCalculation: function (e) {
    // console.log(e.detail)
    let tapIndex = e.detail.tapIndex; // 点击时大分类索引
    let goodIndex = e.detail.goodIndex; // 分类下产品索引
    let count = e.detail.num;

    console.log("count="+count)

    let index = e.detail.tapindex;
    this.setData({
      ['cartList[' + tapIndex + '].cartGoods[' + goodIndex + '].totalPrice']: e.detail.totalPrice, // 组件过来的总价
      ['cartList[' + tapIndex + '].cartGoods[' + goodIndex + '].count']: count,
    })
    // console.log(this.data.cartList)
    //this.updateCount(e.detail.cartId, count)
    //this.calaData()
  },
})